#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    timer = new QTimer(this);
    sec = 0;
    workThread = new WorkThread(this);
    ui->lcdNumber->display(QString::number(sec));

    connect(workThread, SIGNAL(done()), this, SLOT(done()));
    connect(workThread, SIGNAL(finished()),
            workThread, SLOT(deleteLater()));
    connect(timer, SIGNAL(timeout()),this, SLOT(timeOut()));
}

Widget::~Widget()
{
    delete ui;
}

void Widget::done()
{
    timer->stop();
}

void Widget::on_pushButton_clicked()
{
    timer->start(100);
    workThread->start();
}

void Widget::timeOut()
{
    ui->lcdNumber->display(QString::number(++sec));
}
